
#include <cassert>
#include <cstring>
#include <iostream>
#include <mpi.h>
using namespace std;

int main(int argc, char **argv) {
  int rank, num_process;
  MPI_Init(&argc, &argv);
  MPI_Comm_rank(MPI_COMM_WORLD, &rank);
  MPI_Comm_size(MPI_COMM_WORLD, &num_process);

  MPI_Status status;
  MPI_Request req;
  constexpr int mess_length{100};
  char message[mess_length];

  // if(rank != 0)
  // {
  sprintf(message, "greeting from process %d", rank);
  MPI_Isend(message, strlen(message), MPI_CHAR, 0, 1, MPI_COMM_WORLD, &req);
  // }
  // else
  if (rank == 0) {
    for (int i = 0; i < num_process; ++i) {
      MPI_Recv(message, mess_length, MPI_CHAR, i, 1, MPI_COMM_WORLD, &status);
      printf("%s\n", message);
    }
  }

  MPI_Finalize();

  return 0;
}